<?php

namespace app\api\controller\v1\home;

use app\admin\model\DataStoreDecoration;
use app\admin\model\DataStorePhoto;
use app\admin\model\DataStoreUser;
use app\api\controller\Api;

class Decoration extends Api
{


    public function index()
    {

        $rule = [
            'album_id' => 'require',
            'image_id' => 'require',
            'type' => 'require',
        ];
        $message = [
            'album_id.require' => '相册不为空',
            'image_id.require' => '图片不为空',
            'type.require' => '类型不为空',
        ];
        $this->validate($this->post, $rule, $message);
        $list = DataStoreUser::where(['status' => 1])->findOrEmpty();
        if ($list->isEmpty()) $this->error('商铺不存在或未审核铜过');
        $store = new  DataStoreDecoration();
        $save = [];

        $images = DataStorePhoto::where(['album_id' => $this->post['album_id']])->whereIn('id', $this->post['image_id'])->column('image');
        if (empty($images)) $this->error('图片不存在');
        foreach ($images as $v) {
            $save[] = [
                'image' => $v,
                'type' => $this->post['type'],
                'store_id' => $list->id
            ];
        }
        if($store->saveAll($save)){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }




    }

}